package com.huawei.appgallery.forum.option.reply.view;

import android.app.ActionBar;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.forum.base.ui.ForumActivity;
import com.huawei.appgallery.forum.option.api.ICommentReplyActivityProtocol;
import com.huawei.appgallery.forum.option.comment.view.UpdateCommentContentLayout;
import com.huawei.appgallery.forum.option.reply.bean.ReplyResponse;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.hmf.annotation.ActivityDefine;
import com.huawei.hwid.core.constants.HwAccountConstants;
import o.azb;
import o.bcf;
import o.bqx;
import o.bqy;
import o.brc;
import o.brd;
import o.brf;
import o.brj;
import o.bse;
import o.bsv;
import o.byc.c;
import o.byc.d;
import o.byc.e;
import o.byc.f;
import o.byc.j;
import o.byt;
import o.byw;
import o.byw.a;
import o.cbh;
import o.cgv;
import o.BaseRequest;
import o.doo;
import o.evk;
import o.fho;
import o.fiv;
import o.fjo;
import o.fjq;

@ActivityDefine(alias = "option.reply.comment.inner", protocol = ICommentReplyActivityProtocol.class)
public class CommentReplyActivity extends ForumActivity {
    private long ʻॱ;
    private ProgressBar ʽॱ;
    private String ʾ;
    private String ʿ;
    private boolean ˈ = false;
    private TextWatcher ˉ = new TextWatcher(this) {
        final /* synthetic */ CommentReplyActivity ˏ;

        {
            this.ˏ = r1;
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void afterTextChanged(Editable editable) {
            this.ˏ.ˋ(editable);
        }
    };
    private Runnable ˊˊ = new Runnable(this) {
        final /* synthetic */ CommentReplyActivity ˏ;

        {
            this.ˏ = r1;
        }

        public void run() {
            this.ˏ.ˊᐝ();
        }
    };
    private int ˊˋ = 0;
    private fiv ˊᐝ = fiv.ॱ(this);
    private Handler ˋˊ = new Handler(Looper.getMainLooper());
    private UpdateCommentContentLayout ˋॱ;
    private ImageView ͺ;
    private ViewGroup ॱˊ;
    private String ॱˋ = "";
    private String ॱˎ = "";
    private int ᐝॱ;

    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        cgv.ˋ(this, e.ॱ, e.ˎ);
        setContentView(f.ˊ);
        ᐝ();
        ͺ();
        ॱˊ();
    }

    private void ᐝ() {
        ICommentReplyActivityProtocol iCommentReplyActivityProtocol = (ICommentReplyActivityProtocol) this.ˊᐝ.ॱ();
        if (iCommentReplyActivityProtocol != null) {
            this.ʻॱ = iCommentReplyActivityProtocol.getPid();
            this.ॱˎ = iCommentReplyActivityProtocol.getCommentId();
            this.ॱˋ = iCommentReplyActivityProtocol.getReplyId();
            this.ᐝॱ = iCommentReplyActivityProtocol.getType();
            this.ʿ = iCommentReplyActivityProtocol.getToUid();
            this.ʾ = iCommentReplyActivityProtocol.getToUserName();
            this.ˊॱ = iCommentReplyActivityProtocol.getDomainId();
            this.ˊˋ = iCommentReplyActivityProtocol.getSectionId();
        }
        if (this.ʻॱ == 0 && this.ᐝॱ != 4 && this.ᐝॱ != 5) {
            bqx.ॱ("CommentReplyActivity", "mPid == null");
            finish();
        }
    }

    private void ͺ() {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        View findViewById = findViewById(d.ʽॱ);
        azb.ˏ(findViewById);
        ((ViewGroup) findViewById.findViewById(d.ᐝ)).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ CommentReplyActivity ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                this.ˎ.finish();
            }
        });
        ((TextView) findViewById.findViewById(d.ˋˊ)).setText(j.ˋॱ);
        this.ॱˊ = (ViewGroup) findViewById.findViewById(d.ˋॱ);
        this.ॱˊ.setContentDescription(getString(j.ˋॱ));
        this.ॱˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ CommentReplyActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                if (!doo.ˊ(this.ˋ)) {
                    evk.ˏ(this.ˋ, j.ॱˋ, 0).ˋ();
                } else if (!this.ˋ.ˈ) {
                    ((cbh) fho.ˏ().ˋ("User").ॱ(cbh.class)).ˎ(this.ˋ, 15).ˏ(new fjq<Boolean>(this) {
                        final /* synthetic */ AnonymousClass3 ˏ;

                        {
                            this.ˏ = r1;
                        }

                        public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                            if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                                this.ˏ.ˋ.ʼॱ();
                            }
                        }
                    });
                }
            }
        });
        this.ͺ = (ImageView) this.ॱˊ.findViewById(d.ͺ);
        this.ͺ.setImageResource(c.ˊ);
        this.ʽॱ = (ProgressBar) findViewById(d.ʾ);
    }

    private void ॱˊ() {
        this.ˋॱ = (UpdateCommentContentLayout) findViewById(d.ˍ);
        if (TextUtils.isEmpty(this.ʾ)) {
            this.ˋॱ.setHint(getResources().getString(j.ʽ));
        } else {
            ᐝॱ();
        }
        this.ˋॱ.ॱ().addTextChangedListener(this.ˉ);
        this.ˋˊ.postDelayed(this.ˊˊ, 100);
    }

    private void ᐝॱ() {
        if (this.ᐝॱ == 4 || this.ᐝॱ == 5) {
            this.ˋॱ.setHint(getResources().getString(j.ˋॱ) + HwAccountConstants.BLANK + this.ʾ);
            this.ˋॱ.setMaxCount(800);
            return;
        }
        this.ˋॱ.setHint(getResources().getString(j.ˋॱ) + this.ʾ);
    }

    private void ˋ(int i, int i2) {
        ˉ();
        switch (i2) {
            case 0:
                if (i == 0) {
                    evk.ˏ(getString(j.ˊ));
                    finish();
                    return;
                }
                return;
            case 8:
                evk.ˏ(getString(j.ˋ));
                return;
            case 9:
                evk.ˏ(getString(j.ॱ));
                return;
            case 11:
                evk.ˏ(getString(j.ˎ));
                return;
            case 12:
                evk.ˏ(getString(j.ˏ));
                return;
            default:
                evk.ˏ(getString(bse.ˏ.ॱ(i2).ˏ()));
                return;
        }
    }

    private void ʼॱ() {
        String ˊˊ = ˊˊ();
        if (!TextUtils.isEmpty(ˊˊ)) {
            ˊˋ();
            if (this.ᐝॱ == 4 || this.ᐝॱ == 5) {
                ((bcf) fho.ˏ().ˋ("AppComment").ॱ(bcf.class)).ˊ(this, this.ॱˎ, this.ॱˋ, this.ʾ, ˊˊ, new IServerCallBack(this) {
                    final /* synthetic */ CommentReplyActivity ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    }

                    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                        this.ˎ.ˉ();
                        this.ˎ.ˋ(responseBean.getResponseCode(), responseBean.getRtnCode_());
                    }
                });
                return;
            }
            Object ˊ;
            brf o_brf = (brf) fho.ˏ().ˋ("Base").ॱ(brf.class);
            if (TextUtils.isEmpty(this.ʿ)) {
                o_brf.ॱ(byt.METHOD, ReplyResponse.class);
                ˊ = new b(this.ʻॱ, ˊˊ).ˊ(null).ˏ(bsv.ॱ(this.ˊॱ)).ˊ();
            } else {
                o_brf.ॱ(byt.METHOD, ReplyResponse.class);
                byw ˎ = new a(this.ʻॱ, this.ʿ, ˊˊ).ॱ(null).ˊ(bsv.ॱ(this.ˊॱ)).ˎ();
            }
            ((brc) fho.ˏ().ˋ("Base").ॱ(brc.class)).ˋ(ˊ, new brc.e<brj, ReplyResponse>(this) {
                final /* synthetic */ CommentReplyActivity ˎ;

                {
                    this.ˎ = r1;
                }

                public /* synthetic */ void ˋ(Object obj, Object obj2) {
                    ˊ((brj) obj, (ReplyResponse) obj2);
                }

                public /* synthetic */ void ˏ(Object obj, Object obj2) {
                    ˎ((brj) obj, (ReplyResponse) obj2);
                }

                public void ˎ(brj o_brj, ReplyResponse replyResponse) {
                }

                public void ˊ(brj o_brj, ReplyResponse replyResponse) {
                    if (replyResponse.getResponseCode() == 0 && replyResponse.getRtnCode_() == 0) {
                        evk.ˏ(this.ˎ.getString(j.ˊ));
                        this.ˎ.ˉ();
                        this.ˎ.finish();
                        brd.ॱ.ˎ(bqy.ˋ().ˎ(this.ˎ), this.ˎ.ˊॱ, String.valueOf(this.ˎ.ˊˋ), String.valueOf(this.ˎ.ʻॱ), String.valueOf(replyResponse.ˋ()));
                    } else if (replyResponse.getRtnCode_() == 3004) {
                        this.ˎ.ˉ();
                        evk.ˏ(this.ˎ.getString(bse.ˏ.ˏ("reply", 3004)));
                    } else {
                        this.ˎ.ˉ();
                        evk.ˏ(this.ˎ.getString(bse.ˏ.ॱ(replyResponse.getRtnCode_()).ˏ()));
                    }
                }
            });
        }
    }

    private String ˊˊ() {
        String obj = this.ˋॱ.ॱ().getText().toString();
        if (obj.trim().isEmpty()) {
            return "";
        }
        return obj.replaceAll("[\\t\\n\\r]", "[br]");
    }

    private void ˋ(Editable editable) {
        if (editable.length() <= 0 || editable.toString().trim().isEmpty()) {
            this.ॱˊ.setClickable(false);
            this.ͺ.setImageResource(c.ˊ);
            return;
        }
        this.ॱˊ.setClickable(true);
        this.ͺ.setImageResource(c.ॱ);
    }

    public void finish() {
        ˋˊ();
        super.finish();
    }

    private void ˊˋ() {
        this.ˈ = true;
        this.ʽॱ.setVisibility(0);
        this.ͺ.setVisibility(8);
    }

    private void ˉ() {
        this.ˈ = false;
        this.ʽॱ.setVisibility(8);
        this.ͺ.setVisibility(0);
    }

    private void ˊᐝ() {
        Object systemService = getSystemService("input_method");
        if ((systemService instanceof InputMethodManager) && getCurrentFocus() != null) {
            ((InputMethodManager) systemService).showSoftInput(getCurrentFocus(), 2);
        }
    }

    private void ˋˊ() {
        Object systemService = getSystemService("input_method");
        if ((systemService instanceof InputMethodManager) && getCurrentFocus() != null) {
            ((InputMethodManager) systemService).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        }
    }
}
